#include <omp.h>

#include "state.h"
#include "arg.h"

#include <iostream>
#include <cstdlib>

using namespace std;

int main(int argc, char** argv)
{
    //int n,k;

    //arg(argc, argv, n, k);
cout<<"IBEGIN!!!"<<endl;

    my_omp_srand(time(NULL));

    complexd h[] = {
        complexd(1/sqrt(2), 0), complexd( 1/sqrt(2), 0),
        complexd(1/sqrt(2), 0), complexd(-1/sqrt(2), 0)
    };
    Conversion H(2,2,h);

    State state(31);

    double time;
    try {
             time = omp_get_wtime();
            state.randomFill();
            state.norma();
            state.doConversion(H, 1);
            state.norma();
            time = omp_get_wtime() - time;
/*
    for (int num_proc = 1; num_proc < 9; num_proc *= 2) {
            omp_set_num_threads(num_proc);

            time = omp_get_wtime();
            state.randomFill();
            state.norma();
            state.doConversion(H, 1);
            state.norma();
            time = omp_get_wtime() - time;
            cout << time << endl;
            
            time = omp_get_wtime();
            state.randomFill();
            state.norma();
            state.doConversion(H, 17);
            state.norma();
            time = omp_get_wtime() - time;
            cout << time << endl;
            
            time = omp_get_wtime();
            state.randomFill();
            state.norma();
            state.doConversion(H, 31);
            state.norma();
            time = omp_get_wtime() - time;
            cout << time << endl;
        
*/
    } catch (bad_alloc &a) {
        cout << "Everything is bad!!!" << endl;
    } catch (...) {
        cout << "Unknow error!!!" << endl;
    }
cout<<"FINISH!!!"<<endl;
/*
    for (int length = 20; length < 29; length += 4) {
        for (int num_proc = 1; num_proc < 9; num_proc *= 2) {

            State state(length);
            omp_set_num_threads(num_proc);

            time = omp_get_wtime();
            state.randomFill();
            state.norma();
            state.doConversion(H, 1);
            state.norma();
            time = omp_get_wtime() - time;
            cout << time << endl;
            
            time = omp_get_wtime();
            state.randomFill();
            state.norma();
            state.doConversion(H, 17);
            state.norma();
            time = omp_get_wtime() - time;
            cout << time << endl;
            
            time = omp_get_wtime();
            state.randomFill();
            state.norma();
            state.doConversion(H, length);
            state.norma();
            time = omp_get_wtime() - time;
            cout << time << endl;
            
        }
    }
*/

cout<<"FINISH!!!"<<endl;

    return 0;
}
